package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.EduService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class EduController {
    @Autowired
    EduService eduService;

    @RequestMapping("/find1")
    public Object find1(String nowDate){
        List<Map> list = eduService.find1("2021-11-14");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONArray dataArray = new JSONArray();
        for (Map map : list) {
            JSONObject mapObject = new JSONObject();
            mapObject.put("name",map.get("grade"));
            mapObject.put("value",map.get("percent"));
            dataArray.add(mapObject);
        }
        jsonObject.put("data",dataArray);
        return jsonObject;
    }

    @RequestMapping("/find2")
    public Object find2(String nowDate){
        List<Map> list = eduService.find2("2021-04-23");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray mapArray = new JSONArray();
        for (Map map : list) {
            JSONObject mapObject = new JSONObject();
            mapObject.put("name",map.get("name"));
            mapObject.put("value",map.get("sum"));
            mapArray.add(mapObject);
        }
        dataObject.put("mapData",mapArray);
        jsonObject.put("data",dataObject);
        return jsonObject;
    }
}
